package com.wing.user.service;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.bean.copier.CopyOptions;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wing.user.dao.PostDao;
import com.wing.user.model.entity.Post;
import com.wing.user.model.request.PostForm;
import com.wing.user.model.response.PostVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * 岗位表-ServiceImpl
 *
 * @author
 */
@Service
@Slf4j
public class PostServiceImpl extends ServiceImpl<PostDao, Post> implements PostService {

    @Override
    public int add(PostForm postForm) {
        //校验
        Post post =new Post();
        CopyOptions copyOptions = CopyOptions.create()
        .setEditable(Post.class)
        .setIgnoreError(true)
        .setIgnoreNullValue(true);
        BeanUtil.copyProperties(postForm, post, copyOptions);

        return baseMapper.insert(post);
    }

    @Override
    public Page<Post> pageList4app(Page page, Map<String, Object> params) {
        List<PostVO> list = baseMapper.list4app(page, params);
        page.setRecords(list);
        return page;
    }

    @Override
    public PostVO get4appById(Long id) {
        return baseMapper.get4appById(id);
    }
}
